package com.qf.boot2302.util;

import cn.hutool.core.io.FileUtil;

import java.util.HashSet;
import java.util.Random;
import java.util.Set;

public class QfRandomUtil {

    /**
     * 产生指定数量个随机数
     * @param num 数量
     * @param upbound 随机数的上编
     * @return
     */
    public static Set<Integer> produceRandomNum(Integer num, Integer upbound) throws Exception {
        if (num>upbound){
            throw new Exception("num不能大于upbound");
        }
        Random random = new Random();
        Set<Integer> uniqueNumbers = new HashSet<>();
        while (uniqueNumbers.size() < num) {
            int randomNumber = random.nextInt(upbound); // 生成随机数
            uniqueNumbers.add(randomNumber); // 将随机数添加到集合中
        }
        return uniqueNumbers;
    }

    public static void main(String[] args) throws Exception {
        for (int i=0;i<5;i++) {
            Set<Integer> integers = QfRandomUtil.produceRandomNum(30, 29);
            System.out.println(integers);
        }
    }
}
